package com.example.chenz.weght;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.content.Intent;

public class MainActivity extends AppCompatActivity {
    // Called when the activity is first created.
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //载入activity_main.xml Layout
        setContentView(R.layout.activity_main);
        //以findViewById()取得Button对象，并加入onClickListener
        Button b1 = (Button) findViewById(R.id.btn_calculate);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                //T000 Auto-generated method stub
                EditText et = (EditText)findViewById(R.id.et_height);
                double height = Double.parseDouble(et.getText().toString());
                //获取选择的性别
                String sex="";
                RadioButton bg = (RadioButton)findViewById(R.id.rb_male);
                if(bg.isChecked())
                    sex="M";
                else
                    sex="F";
                //new一个Intent对象，并指定class
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,Result.class);
                //new一个Bundle对象，并将要传递的数据传入
                Bundle bundle = new Bundle();
                bundle.putDouble("height",height);
                bundle.putString("sex",sex);
                //将Bundle对象assign给Intent
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }
}
